package cn.com.czpb.client.module.news.dialog;

import android.app.Activity;
import android.view.Gravity;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
import android.widget.TextView;

import cn.com.czpb.client.R;

import butterknife.ButterKnife;

/**
 * Created by 猪猪侠 on 2017/7/5.
 */

public class CommPop extends PopupWindow implements View.OnClickListener{
    private String msg;
    private Activity context;
    private TextView tv_copy,tv_report,tv;
    private int type;//0、正常评论  1、回复评论
    public interface OnClickListeners {
        void OnClicked(View view);
    }
    private OnClickListeners listener;
    public CommPop(Activity a,TextView tv,OnClickListeners listener) {
        this.tv=tv;
        this.context = a;
        this.listener=listener;
        View view = a.getLayoutInflater().inflate(R.layout.popup_window_comm, null);
        tv_copy=view.findViewById(R.id.tv_copy);
        tv_report=view.findViewById(R.id.tv_report);
        tv_copy.setOnClickListener(this);
        tv_report.setOnClickListener(this);
        ButterKnife.bind(this, view);
        setContentView(view);
        setWindowLayoutMode(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
        setOutsideTouchable(true);


    }

    public void showAsPullUp(View anchor, int xoff, int yoff) {

        //保存anchor在屏幕中的位置
        int[] location = new int[2];
        //保存anchor上部中点
        int[] anchorCenter = new int[2];
        //读取位置anchor座标
        anchor.getLocationOnScreen(location);
        //计算anchor中点
        anchorCenter[0] = location[0] / 2 + anchor.getWidth() / 2 - 150;
        anchorCenter[1] = location[1];
        super.showAtLocation(anchor, Gravity.TOP | Gravity.LEFT, anchorCenter[0] - xoff, anchorCenter[1] - 50 + yoff - anchor.getHeight());
    }

//    @OnClick({R.id.tv_copy, R.id.tv_report})
//    public void onViewClicked(View view) {
//
//    }

//    @Override
//    public void dismiss() {
//        super.dismiss();
//        switch (type) {
//            case 0:
//                tv.setBackgroundColor(context.getResources().getColor(R.color.white));
//                break;
//            case 1:
//                tv.setBackgroundColor(context.getResources().getColor(R.color.color_f5f5f5));
//                break;
//        }
//
//    }

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.tv_copy: {
//                ClipboardManager cmb = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
//                cmb.setText(msg);
//                TUtils.toast("已复制");
                listener.OnClicked(view);
                this.dismiss();
            }
            break;
            case R.id.tv_report: {
//                ClipboardManager cmb = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
//                cmb.setText(msg);
//                TUtils.toast(msg);
                this.dismiss();
                listener.OnClicked(view);
            }
            break;
        }

    }

    @Override
    public void dismiss() {
        super.dismiss();
        tv.setBackgroundColor(context.getResources().getColor(R.color.white));
    }
}
